package com.smmisia.article.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smmisia.article.entity.Banner;
import com.smmisia.article.exception.customException;
import com.smmisia.article.mapper.BannerMapper;
import com.smmisia.article.service.BannerService;
import com.smmisia.common.Result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner>
    implements BannerService{

    @Autowired
    private BannerMapper bannerMapper;

    @Override
    public Result<List<Banner>> banner() {
        List<Banner> banners = bannerMapper.selectList(null);
        //List<String> list = banners.stream().map(Banner::getImage).collect(Collectors.toList());
        return Result.ok(banners);
    }

    @Override
    public Result<Banner> add(String url) {
        Banner banner = new Banner();
        banner.setImage(url);
        int insert = bannerMapper.insert(banner);
        Assert.isTrue(insert == 1, () -> new customException("添加失败"));
        return Result.ok(banner);
    }

    @Override
    public Result<String> delete(Integer id) {
        int result = bannerMapper.deleteById(id);
        Assert.isTrue(result == 1, () -> new customException("删除失败"));
        return Result.ok("删除成功");
    }
}




